#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using Gizmox.WebGUI.Common.Interfaces;

#endregion

namespace MT.Mail.WebClient
{
    public partial class LoginForm : Form, ILogonForm
    {
        public LoginForm()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            //TODO: add a resource description
            errortxtUserName.SetError(txtUserName, string.Empty);
            errortxtPassword.SetError(txtPassword, string.Empty);

            if (txtUserName.Text.Equals(string.Empty) || txtPassword.Text.Equals(string.Empty))
            {
                if (txtUserName.Text.Equals(string.Empty))
                    errortxtUserName.SetError(txtUserName, "Insert username.");

                if (txtPassword.Text.Equals(string.Empty))
                    errortxtPassword.SetError(txtPassword, "Insert password.");

                return;
            }

            MT.Mail.Service.MailService ms = new MT.Mail.Service.MailService();

            if (ms.Authenticate(txtUserName.Text, txtPassword.Text))
            {
                Context.Session.IsLoggedOn = true;
                Context.Session["userName"] = txtUserName.Text;
                Context.Session["password"] = txtPassword.Text;
                this.Close();
            }
            else
            {
                MessageBox.Show("Username or password incorrect.", "Warning");
            }
        }
    }
}